CREATE function [dbo].[GetUsedPTOHrs](@userID int,@startDate datetime, @endDate dateTime)
returns float
as
begin
declare @ptoHrs float
declare @RolledPTOHours int
	
	select @RolledPTOHours = PTOHoursRolledIntoCurrentYear from dbo.Users
	where UserID=@userID

SELECT     @ptoHrs = coalesce(SUM(dbo.EntryLog.Duration),0)
FROM       dbo.EntryLog 
WHERE     (dbo.EntryLog.UserID = @userID) and
		  (dbo.EntryLog.CategoryID = 7 OR dbo.EntryLog.CategoryID = 13) and
		  (dbo.EntryLog.EntryDate between @startDate and @endDate)
		  
return @ptoHrs-@RolledPTOHours
end

